package com.xebia.lightning.web;

import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.roo.addon.web.mvc.controller.RooWebScaffold;
import org.springframework.roo.addon.web.mvc.controller.json.RooWebJson;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.xebia.lightning.domain.JobAggregate;

@RequestMapping("/jobaggregates")
@Controller
@RooWebScaffold(path = "jobaggregates", formBackingObject = JobAggregate.class)
@RooWebJson(jsonObject = JobAggregate.class)
public class JobAggregateController {

    @RequestMapping(value = "/json/{id}")
    @ResponseBody
    public ResponseEntity<String> showJson(@PathVariable("id") String id) {
        JobAggregate jobaggregate = jobAggregateService.findJobAggregateForLocation(id);
        System.out.println(jobaggregate);
        HttpHeaders headers = new HttpHeaders();
        headers.add("Content-Type", "application/text; charset=utf-8");
        if (jobaggregate == null) {
            return new ResponseEntity<String>(headers, HttpStatus.NOT_FOUND);
        }
        return new ResponseEntity<String>(jobaggregate.toJson(), headers, HttpStatus.OK);
    }
}
